import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  // 后端服务相关配置
  server: {
    host: '0.0.0.0',
    port: 5198,
    https: false,
    // 后端服务器代理配置
    proxy: {
      '^/api': {
        // 后台服务器代理
        target: 'http://localhost:8099',
        // 允许跨域
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    },
    hmr: true,
  }
})
